/*
 * Copyright 2019 Zhang XueHai
 * you may not use this file except in compliance with the License.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhangxuehai.android.pdfviewer.annotation;

import android.graphics.Canvas;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zhangxuehai.android.pdfviewer.PDFView;
import com.shockwave.pdfium.util.Size;

import java.util.Objects;
import java.util.UUID;

/**
 * 注释类
 * @author 章学海
 * @date 2019/12/26
 */
public abstract class BaseAnnotation<Data,Pen extends com.zhangxuehai.android.pdfviewer.annotation.pen.Pen<Data>> {
    private String id;
    public int page;
    public Pen pen;
    public Data data;
    public AnnotationType annotationType;
    public Size pageSize;
    public transient boolean drawed;

    BaseAnnotation(@NonNull AnnotationType annotationType, @IntRange(from = 0) int page, Size pageSize,@NonNull Pen pen) {
        this.id = UUID.randomUUID().toString();
        this.annotationType = annotationType;
        this.page = page;
        this.pen = pen;
        this.pageSize = pageSize;
    }

    public void draw(Canvas canvas, float scale, int basePenWidth, PDFView pdfView){
        pen.draw(data,canvas,scale,basePenWidth,pdfView,page);
        drawed = true;
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        return Objects.equals(obj,id);
    }

    @Override
    public int hashCode() {
        if (id==null) {
            return 0;
        }else{
            return id.hashCode();
        }
    }
}
